/**
 * 
 */
package com.lehecai.core.api.event;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.lehecai.core.api.AbstractApiResultBean;
import com.lehecai.core.util.CoreDateUtils;

/**
 * 道具
 * @author He Wang
 *
 */
public class PropInfo extends AbstractApiResultBean {
	
	public static final String QUERY_ID = "id";
	public static final String QUERY_TYPE = "type";
	
	public static final String SET_NAME = "name";
	public static final String SET_TYPE = "type";
	public static final String SET_PROPERTIES = "properties";
    public static final String SET_PROPPIC = "pic";

	private Long id;		       //编码
	private String name;           //名称
	private PropType type;	       //道具类型
	private String properties;     //道具属性
	private Date createdTime;      //创建时间
	private List<PropProperties> propertiesList;//道具属性
    private String propPic;//道具图片

	public static PropInfo convertFromJSONObject(JSONObject object) {
		if (object == null) {
			return null;
		}
		PropInfo propInfo = new PropInfo();
		propInfo.id = getLong(object, "id");
		propInfo.name = getString(object, "name");
		propInfo.type = PropType.getItem(getInt(object, "type"));
		propInfo.createdTime = CoreDateUtils.parseDate(getString(object, "create_at"), CoreDateUtils.DATETIME);
		propInfo.properties = getString(object, "properties");
        propInfo.propPic = getString(object, "pic");
		return propInfo;
	}
	
	public static List<PropInfo> convertFromJSONArray(JSONArray array) {
		if (array == null) {
			return null;
		}
		List<PropInfo> list = new ArrayList<PropInfo>();
		for (Iterator<?> iterator = array.iterator(); iterator.hasNext();) {
			JSONObject object = (JSONObject) iterator.next();
			list.add(convertFromJSONObject(object));
		}
		return list;
	}
	
	public static String convertFromPropertiesList(List<PropProperties> propertiesList) {
		if (propertiesList == null || propertiesList.size() == 0) {
			return null;
		}
		JSONObject obj = new JSONObject();
		for (PropProperties p : propertiesList) {
			obj.put(p.getField(), p.getValue());
		}
		return obj.toString();
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getId() {
		return id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setType(PropType type) {
		this.type = type;
	}

	public PropType getType() {
		return type;
	}

	public void setProperties(String properties) {
		this.properties = properties;
	}

	public String getProperties() {
		return properties;
	}

	public void setCreatedTime(Date createdTime) {
		this.createdTime = createdTime;
	}

	public Date getCreatedTime() {
		return createdTime;
	}

	public void setPropertiesList(List<PropProperties> propertiesList) {
		this.propertiesList = propertiesList;
	}

	public List<PropProperties> getPropertiesList() {
		return propertiesList;
	}

    public String getPropPic() {
        return propPic;
    }

    public void setPropPic(String propPic) {
        this.propPic = propPic;
    }
}
